/************************************************************************
 *
 * ctype.h 
 *
 * (c) Copyright 1996-2004 Analog Devices, Inc.  All rights reserved.
 * $Revision: 1.1 $
 ************************************************************************/

#pragma once
#ifndef __NO_BUILTIN
#pragma system_header /* ctype.h */
#endif

#ifndef __CTYPE_DEFINED
#define __CTYPE_DEFINED

#ifdef __cplusplus
  extern "C" {
#endif

#ifdef __TS_BYTE_ADDRESS
#define _Libc_ct_temp _Libc_ct_temp_ba
#define _Libc_ct_tab  _Libc_ct_tab_ba
#endif

#define _LIBC_CT_UPPER   0x01
#define _LIBC_CT_LOWER   0x02
#define _LIBC_CT_DIGIT   0x04
#define _LIBC_CT_CTLSPC  0x08 /* FF NL CR HT VT */
#define _LIBC_CT_PUNCT   0x10
#define _LIBC_CT_CTL     0x20 /* backspace, bell, etc. */
#define _LIBC_CT_XDIGIT  0x40
#define _LIBC_CT_SPC     0x80 /* the space char */

#define _LIBC_CT_ALNUM   (_LIBC_CT_UPPER|_LIBC_CT_LOWER|_LIBC_CT_DIGIT)
#define _LIBC_CT_ALPHA   (_LIBC_CT_UPPER|_LIBC_CT_LOWER)
#define _LIBC_CT_GRAPH   (_LIBC_CT_ALNUM|_LIBC_CT_PUNCT)
#define _LIBC_CT_PRINT   (_LIBC_CT_GRAPH|_LIBC_CT_SPC)
#define _LIBC_CT_SPACE   (_LIBC_CT_SPC|_LIBC_CT_CTLSPC)
#define _LIBC_CT_CONTROL (_LIBC_CT_CTL|_LIBC_CT_CTLSPC)
 
int isalnum(int);
int isalpha(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);
int tolower(int);
int toupper(int);

#ifdef __ANALOG_EXTENSIONS__
  int isascii(int);
  int toascii(int);
#endif /* __ANALOG_EXTENSIONS__ */

extern const short _Libc_ct_tab[];
extern int _Libc_ct_temp;

#define _LIBC_CT_SAVE(c) _Libc_ct_temp=(c),
#define _LIBC_CT_SUBST(c) _Libc_ct_temp
#define _LIBC_CT_TEST(c,m) (_LIBC_CT_SAVE(c) \
  _LIBC_CT_SUBST(c)&(~0x7f)?0:_Libc_ct_tab[_LIBC_CT_SUBST(c)]&m)

#define isalnum(c)  _LIBC_CT_TEST(c,_LIBC_CT_ALNUM)
#define isalpha(c)  _LIBC_CT_TEST(c,_LIBC_CT_ALPHA)
#define iscntrl(c)  _LIBC_CT_TEST(c,_LIBC_CT_CONTROL)
#define isdigit(c)  _LIBC_CT_TEST(c,_LIBC_CT_DIGIT)
#define isgraph(c)  _LIBC_CT_TEST(c,_LIBC_CT_GRAPH)
#define islower(c)  _LIBC_CT_TEST(c,_LIBC_CT_LOWER)
#define isprint(c)  _LIBC_CT_TEST(c,_LIBC_CT_PRINT)
#define ispunct(c)  _LIBC_CT_TEST(c,_LIBC_CT_PUNCT)
#define isspace(c)  _LIBC_CT_TEST(c,_LIBC_CT_SPACE)
#define isupper(c)  _LIBC_CT_TEST(c,_LIBC_CT_UPPER)
#define isxdigit(c) _LIBC_CT_TEST(c,_LIBC_CT_XDIGIT)

#define tolower(c) (_LIBC_CT_SAVE(c) \
  _LIBC_CT_SUBST(c)<65||_LIBC_CT_SUBST(c)>90?_LIBC_CT_SUBST(c): \
  _LIBC_CT_SUBST(c)+32)
#define toupper(c) (_LIBC_CT_SAVE(c) \
  _LIBC_CT_SUBST(c)<97||_LIBC_CT_SUBST(c)>122?_LIBC_CT_SUBST(c): \
  _LIBC_CT_SUBST(c)-32)

#ifdef __ANALOG_EXTENSIONS__
  #define isascii(c) (!((c)&(~0x7f)))
  #define toascii(c) ((c)&0x7f)
#endif

#ifdef __cplusplus
  }
#endif

#endif /* __CTYPE_DEFINED */
